<template>
  <Layout>
    <div ref="miancontainer" class="main-container" v-loading="isLoading">
      <BlogDetail :blog="data" v-if="data" />
      <BlogComment v-if="!isLoading" />
    </div>
    <template #right>
      <div class="right-container" v-loading="isLoading">
        <BlogToc :toc="data.toc" v-if="data" />
      </div>
    </template>
  </Layout>
</template>

<script>
import { debunce } from "@/utils";
import fetchData from "@/mixins/fetchData.js";
import mainScroll from "@/mixins/mainScroll.js";
import { getBlog } from "@/api/blog.js";
import Layout from "@/components/Layout";
import BlogComment from "./components/BlogComment.vue";
import BlogDetail from "./components/BlogDetail.vue";
import BlogToc from "./components/BlogToc.vue";
import { titleController } from "@/utils";
export default {
  mixins: [fetchData({}), mainScroll("miancontainer")],
  components: { Layout, BlogDetail, BlogToc, BlogComment },
  data: () => ({
    scrollTop: 0,
  }),

  updated() {
    // 回到原来的位置 过程
    const hash = location.hash;
    location.hash = "";
    setTimeout(() => {
      location.hash = hash;
    }, 50);
  },
  methods: {
    async fetchData() {
      let resp = await getBlog(this.$route.params.id);
      //   resp = null;
      if (!resp) {
        this.$router.push({ path: "/404" });
        titleController.setRouteTitle("404");
      } else {
        titleController.setRouteTitle(resp.title);
      }

      return resp;
    },
  },
};
</script>

<style lang='less' scoped>
.main-container {
  overflow-y: auto;
  height: 100%;
  box-sizing: border-box;
  padding: 20px;
  position: relative;
}
.right-container {
  width: 300px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 20px;
  position: relative;
}
</style>
